<template>
  <div class="app-container">
    <el-form v-model="query" inline label-width="80px" size="small">
      <el-form-item label="商品名称">
        <el-input v-model="query.name" placeholder="请输入商品名称" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" type="primary" @click="search" size="mini">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="list" v-loading="loading" stripe :cell-style="{padding:'5px'}">
      <el-table-column label="商品名称"  align="center" prop="name" />
      <el-table-column label="单位"  align="center" prop="inStockUnit" />
      <el-table-column label="进价"  align="center" prop="purchaseTotalPrice" />
      <el-table-column label="类别"  align="center" prop="" >
        <template slot-scope="scope">
          {{scope.row.firstTypeName}} / {{scope.row.secondTypeName}}
        </template>
      </el-table-column>
      <el-table-column label="商品图片" align="center" prop="imgUrl">
        <template slot-scope="scope">
          <el-image :src="scope.row.imgUrl" v-if="scope.row.imgUrl"  alt="" style="width: 30px;height: 30px" :preview-src-list="[scope.row.imgUrl]"></el-image>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import {goodsList} from "@/api/goods";

export default {
  name: "index",
  data() {
    return {
      query: {
        pageNum: 1,
        pageSize: 20,
        name: ''
      },
      list: [],
      total: 0,
      loading: false
    }
  },
  methods: {
    search() {
      this.query.pageNum = 1;
      this.getList()
    },
    getList() {
      this.loading = true
      goodsList(this.query).then(res=>{
        this.list = res.rows;
        this.total = res.total
      }).finally(() => {
        this.loading = false
      })
    }
  },
  created() {
    this.getList()
  }
}
</script>



<style scoped lang="scss">

</style>
